import { linkBoxJson,linkQuestion,qaList,updateQa,deleteQa,questionAtlas } from '@/services/user';
export default {
  namespace: 'rightContent',
  state: {
    total: 0,
    items: [],
    loading: true,
  },
  effects: {
    *linkBoxJson({ payload, callback }, { call, put }) {
      const response = yield call(linkBoxJson, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *linkQuestion({ payload, callback }, { call, put }) {
      const response = yield call(linkQuestion, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *qaList({ payload, callback }, { call, put }) {
      const response = yield call(qaList, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *updateQa({ payload, callback }, { call, put }) {
      const response = yield call(updateQa, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *deleteQa({ payload, callback }, { call, put }) {
      const response = yield call(deleteQa, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *graphQuestions({ payload, callback }, { call, put }) {
      const response = yield call(questionAtlas, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
